import { FormItem } from "@/components/SearchForm/formTypes";
import { RATE_LIST, TASK_KEY } from "@/constants";

export const getModalFields = (data): FormItem[] => [
  {
    type: "Select",
    formItemProps: {
      name: "taskKey",
      label: `任务key值`,
    },
    props: {
      disabled: !!data,
      options: TASK_KEY,
    },
  },
  {
    type: "Input",
    formItemProps: {
      name: "name",
      label: "任务名称",
      rules: [{ required: true }],
    },
  },
  {
    type: "Input",
    formItemProps: {
      name: "desc",
      label: "任务描述",
    },
  },
  {
    type: "Select",
    formItemProps: {
      name: "rate",
      label: "上报间隔单位",
    },
    props: {
      options: RATE_LIST,
    },
  },
  {
    type: "InputNumber",
    formItemProps: {
      name: "cycle",
      label: "上报间隔",
      initialValue: 1,
      rules: [{ required: true }],
    },
    props: {
      min: 1,
    },
  },
  ...(!data
    ? ([
        {
          type: "Switch",
          formItemProps: {
            name: "state",
            label: "任务创建后立即开启",
            valuePropName: "checked",
            initialValue: true,
          },
        },
      ] as FormItem[])
    : []),
];
